//
//  QDChangeCityVC.m
//  QuickDoctor
//
//  Created by 李伟 on 2016/12/21.
//  Copyright © 2016年 Eric. All rights reserved.
//

#import "QDChangeCityVC.h"
#import "QDCityModel.h"
#import "QDCityTableViewCell.h"
#import "QDMainViewController.h"
static NSString* cellID = @"cellID";
@interface QDChangeCityVC ()<UITableViewDelegate,UITableViewDataSource>


@end

@implementation QDChangeCityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

#pragma mark
#pragma mark - 搭建界面
- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc]init];
    
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
}


#pragma mark
#pragma mark - TBDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return  self.modelList[self.tempIndex.row].cities.count;
;
}

- (QDCityTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    QDCityTableViewCell *cell = [[QDCityTableViewCell alloc]init];
    
    QDCityModel * model = self.modelList[self.tempIndex.row];
    
    cell.name.text = model.cities[indexPath.row];
    
    return cell;
}

#pragma mark
#pragma mark - TBDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //通知
    NSString *cityName = self.modelList[self.tempIndex.row].cities[indexPath.row];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"city" object:cityName userInfo:nil];
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
    
}

@end
